// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/EmergencyDrillApi'

import OneClass from '@api/base/model/EmergencyDrillReq'
import BaseClass from '@api/base/model/EmergencyDrillDto'

const CLIENT = CORE.grpcCLIENT(Client)

const BASE = [BaseClass, 'dto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async getOne({ id }, TIP = '查询详情') {
    const DTO = CORE.grpcDTO(OneClass, { id }, BASE)
    const resp = await CORE.grpc(TIP, CLIENT, 'emergencyDrillDetail', DTO)
    return { ...resp, ...resp.emergencyDrillDto }
  },
  transOne(obj) {
    obj.duringTime = 0
    obj.emergencyDrillStepDtos.forEach((item) => {
      item.duringTime = item.endTime - item.beginTime
      item.duringTime -= item.duringTime % 1000
      obj.duringTime += item.duringTime
      item.duringText = CORE.numDuringTwo(item.duringTime / 1000 | 0)
    })
    obj.duringText = CORE.numDuringTwo(obj.duringTime / 1000 | 0)
    return obj
  },
}
